#-*-coding:utf-8-*-#

import os
import pandas as pd
import matplotlib.pyplot as plt
os.chdir('PATH')

dd=pd.read_csv('Data_Extended1a.csv',index_col=0) # Control SIR result of drought
ww=pd.read_csv('Data_Extended2a.csv',index_col=0) # Control SIR result of wildfire

dr = pd.read_csv('Data_Extended6ac.csv', index_col=0) # Factor 5 experiment of drought
wf = pd.read_csv('Data_Extended6bd.csv', index_col=0) # Factor 5 experiment of wildfire

EMM = pd.read_csv('Data_Fig2a_1.csv', index_col=0)
Emp_data = EMM[112:]
Emp_data['Count'] = Emp_data['Count'] - Emp_data['Count'][112]
Emp_data = Emp_data.reset_index(drop=True)

Emp_data_diff = (Emp_data.Count - Emp_data.Count.shift()).fillna(0)

WEMM = pd.read_csv('Data_Fig2c_1.csv', index_col=0)
WEmp_data = WEMM[70:]
WEmp_data['Count'] = WEmp_data['Count'] - WEmp_data['Count'][70]
WEmp_data = WEmp_data.reset_index(drop=True)

WEmp_data_diff = (WEmp_data.Count - WEmp_data.Count.shift()).fillna(0)


plt.rcParams['font.size'] = 14
xx = 194


"""


Extended Data5a


"""

plt.figure(dpi=400,figsize=(7,4.6))
plt.fill_between(range(0,xx,1), dd['bR'][:xx]/20164*100,dd['tR'][:xx]/20164*100,facecolor='gray',interpolate=True
                 , alpha = 0.3)
plt.plot(range(0,xx,1), dd['mR'][:xx]/20164*100, color='black')
plt.plot(range(0,xx,1), Emp_data[:xx].Count/20164*100, color='black',linestyle='dotted',alpha=0.5)

plt.axhline(y=0,color='black',linestyle='-',linewidth=1)
plt.xticks(range(0,xx,45))
plt.xlim([0,xx-1])
plt.ylim([-9,80])
plt.show()




"""


Extended Data5b


"""

plt.figure(dpi=400,figsize=(7,4.6))
plt.fill_between(range(0,xx,1), ww['bR'][:xx]/4592*100,ww['tR'][:xx]/4592*100,facecolor='gray',interpolate=True
                 , alpha = 0.3)
plt.plot(range(0,xx,1), ww['mR'][:xx]/4592*100, color='black')
plt.plot(range(0,xx,1), WEmp_data[:xx].Count/4592*100, color='black',linestyle='dotted',alpha=0.5)

plt.axhline(y=0,color='black',linestyle='-',linewidth=1)
plt.xticks(range(0,xx,45))
plt.xlim([0,xx-1])
plt.ylim([-9,80])
plt.show()




"""


Extended Data5c


"""


df = pd.DataFrame()

plt.figure(dpi=400,figsize=(7,4.6))
plt.plot(range(0,xx,1), Emp_data_diff[:xx]/1800*100, color='black',linestyle='dotted',alpha=0.5)
plt.fill_between(range(0,xx,1), dr['C_b'][:xx]/20164*100,dr['C_t'][:xx]/20164*100,facecolor='gray',interpolate=True
                 , alpha = 0.3)
plt.plot(range(0,xx,1), dr['C_m'][:xx]/20164*100, color='black')
plt.axhline(y=0,color='black',linestyle='-',linewidth=1)
plt.xticks(range(0,xx,45))
plt.xlim([0,xx-1])
plt.ylim([-9,50])
plt.show()


"""


Extended Data4d


"""



plt.figure(dpi=400,figsize=(7,4.6))
plt.plot(range(0,xx,1), WEmp_data_diff[:xx]/600*100, color='black',linestyle='dotted',alpha=0.5)
plt.fill_between(range(0,xx,1), wf['C_b'][:xx]/4592*100,wf['C_t'][:xx]/4592*100,facecolor='gray',interpolate=True
                 , alpha = 0.3)
plt.plot(range(0,xx,1), wf['C_m'][:xx]/4592*100, color='black')
plt.axhline(y=0,color='black',linestyle='-',linewidth=1)
plt.xticks(range(0,xx,45))
plt.xlim([0,xx-1])
plt.ylim([-9,50])
plt.show()
